package com.example.springboottest.example.spi;

import com.example.springboottest.example.singleton.Sngleton4;

import java.util.ServiceLoader;

public class SPITest {
    public static void main(String[] args) {
//        try {
//            Class.forName("com.example.springboottest.example.spi.impl.ChineseHello");
//        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        }
//
//        ClassLoader cl = Sngleton4.class.getClassLoader();
//        while (cl != null) {
//            System.out.println(cl.toString());
//            cl = cl.getParent();
//        }

        ServiceLoader<IHello> hellos = ServiceLoader.load(IHello.class);
        for (IHello hello : hellos) {
            System.out.println(hello.sayHello());
        }
//        hello.stream().forEach(System.out::println);
    }
}
